
var current = 1;

function moreCommentlist(aid) {
    current=current+1;
    var obj = {
        nid:aid,
        typees:0,
        currentPage:current
    };

    console.log("current========="+current);

    $.post(basePath+"moreDiscuss",obj,function (data) {
        console.log(data);
        $("#commenList").append(data);
    })


};

function collect(articleId) {
    var obj = {
        nid:articleId,
        type:0
    };

    $.post(basePath+"addCollect",obj,function (data) {
        console.log(data);
        if(data.code === 100){
            layer.msg("您还未登录，请先登录");
        }else{
            layer.msg(data.message);
            if(data.success){
                window.location.reload();
            }
        }

    });

}

function addlike(element,userEmail,articleId,discussId) {

    console.log("articleId       "+articleId);
    console.log("discussId       "+discussId);

    var obj = {
        newsid:articleId,
        did:discussId
    };

    console.log(obj);

    $.post(basePath+"addlike",obj,function (data) {
        if(data.code === 100){
            layer.msg("您还未登录，请先登录");
        }else{
            console.log(data);
            layer.open({
                type:0,
                content:data
            });
            if("点赞成功" === data){
                window.location.reload();
            }
        }
    });

}

function clickReply(id) {
    var list = document.getElementsByClassName("posi-input");
    for (var i = 0; i < list.length; i++) {
        list[i].setAttribute("style","display: none;");
    }
    console.log(id);
    console.log(document.getElementById(id).innerHTML);
    document.getElementById(id).setAttribute("style","");
}

function reply(articleId,fid,contentId){
    var content = $("#"+contentId).val();
    console.log("-----------------评论的内容："+content);
    if(content === ""){
        layer.msg("请输入您评论的内容！！！");
        return;
    }

    var obj = {
        fid:fid,
        nid:articleId,
        content:content,
        typees:0
    };
    $.post(basePath+"addDiscuss",obj,function (data) {
        if(data.code === 100){
            layer.msg("您还没有登录，请先登录")
        }else{
            layer.msg(data.message);
            if(data.success){
                window.location.reload();
            }
        }

    })

}

function discuss(){
    var content = $(".textarea").val();
    console.log("-----------------评论的内容："+content);
    if(content === ""){
        layer.msg("请输入您评论的内容！！！");
        return;
    }

    var obj = {
        nid:$(".textarea-train").attr("name"),
        content:$(".textarea-train").val(),
        typees:0
    };
    $.post(basePath+"addDiscuss",obj,function (data) {
        if(data.code === 100){
            layer.msg("您还没有登录，请先登录")
        }else{
            layer.msg(data.message);
            if(data.success){
                window.location.reload();
            }
        }
    })

}

function replys(moreId,fid,articleId,replyNum){
    var obj = {
        fid:fid,
        nid:articleId,
        typees:0

    };

    if($("#"+fid+" span").html() === "收起回复"){
        $("#"+fid+" span").html(replyNum+"条回复");
        $("#"+fid+" img").removeClass("arrow-img-train");
        $("#"+moreId).attr("style","display:none");
        return ;
    }

    console.log("moreId:"+moreId);

    $.post(basePath+"findDiscussByFid",obj,function (data) {
        console.log(data);
        if(data.code === 100){
            layer.msg("您还没有登录，请先登录")
        }else{
            $("#"+moreId).attr("style","");
            $("#"+fid+" span").html("收起回复");
            $("#"+fid+" img").addClass("arrow-img-train");
            $("#"+moreId).html(data);
        }

    })
}

$(function () {
    $("#discuss-btn").click(discuss);

    $(".textarea").click(function () {
        $(".textarea-train").hide();
        //$(".textarea-train").hide();
        $(".textarea").addClass("textarea-train");
        $(".textarea").parent().css("height", "auto");
        $(".textarea").next().css("position", "static");
    });

    $(".input").click(function () {
        $(".textarea-train").hide();
        //$(".textarea-train").hide();
        $(".input").addClass("textarea-train");
        $(".input").parent().css("height", "auto");
        $(".input").next().css("position", "static");
    });

});


